package com.glsc.ngateway.platform.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.OwnCloudSystemDirConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author xuchang
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude
@Builder
public class SystemRelatedFileConfigVo {
    @ApiModelProperty(value = "最新配置")
    List<SystemRelatedFileConfigDetailVo> lastConfig;
    @ApiModelProperty(value = "最新配置-路径集合")
    Set<String> lastConfigPathSet;

    @ApiModelProperty(value = "快照，时间排序")
    Map<String, List<SystemRelatedFileConfigDetailVo>> records;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonInclude
    @Builder
    public static class SystemRelatedFileConfigDetailVo {
        @ApiModelProperty(value = "文件类别，text/doc/docx/ppt等")
        String fileType;
        @ApiModelProperty(value = "文件名")
        String title;
        @ApiModelProperty(value = "生成唯一id")
        String key;
        @ApiModelProperty(value = "生成唯一id")
        String path;
        @ApiModelProperty(value = "父path")
        String parentPath;
        @ApiModelProperty(value = "子目录")
        Set<SystemRelatedFileConfigDetailVo> children;
        @Builder.Default
        @ApiModelProperty(value = "是否生效")
        boolean valid = false;

        @Builder.Default
        @ApiModelProperty(value = "默认展开")
        boolean expanded = true;
        @Builder.Default
        @ApiModelProperty(value = "能否移动目录到其下")
        boolean canMoveIn = true;
        @Builder.Default
        @ApiModelProperty(value = "是否为系统目录内的目录")
        boolean sysInsideDir = true;

        @JsonIgnore
        Long fileid;
        @JsonIgnore
        Long parentId;
        @JsonIgnore
        Long level;

        public static SystemRelatedFileConfigDetailVo convertFrom(OwnCloudSystemDirConfig config) {
            return SystemRelatedFileConfigDetailVo.builder()
                    .fileid(config.getId())
                    .title(config.getName())
                    .path(config.getPath())
                    .key(config.getPath())
                    .parentId(config.getParentId())
                    .parentPath(config.getParentPath())
                    .valid(config.isValid())
                    .build();
        }
    }
}
